Adding some strings and geometry algorithms to notebook.
[andmenj-acm.git] / Mi manual de algoritmos / version_actual / src / geometria / distance_point_to_line.tex
blobee1a0bed13ce23e6382f597bfe867dce419c329d
1 % Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite
3 {\ttfamily \raggedright {
4 \noindent
5 \mbox{}\textit{\textcolor{Brown}{/*}} \\
6 \mbox{}\textit{\textcolor{Brown}{\ \ Returns\ the\ closest\ distance\ between\ point\ pnt\ and\ the\ line\ that\ passes\ through\ points\ a\ and\ b}} \\
7 \mbox{}\textit{\textcolor{Brown}{\ \ Idea\ by:\ }}\underline{\texttt{\textcolor{Blue}{http://local.wasp.uwa.edu.au/}}}\textit{\textcolor{Brown}{\textasciitilde{}pbourke/geometry/pointline/}} \\
8 \mbox{}\textit{\textcolor{Brown}{\ */}} \\
9 \mbox{}\textcolor{ForestGreen}{double}\ \textbf{\textcolor{Black}{distance$\_$point$\_$to$\_$line}}\textcolor{BrickRed}{(}\textbf{\textcolor{Blue}{const}}\ point\ \textcolor{BrickRed}{\&}a\textcolor{BrickRed}{,}\ \textbf{\textcolor{Blue}{const}}\ point\ \textcolor{BrickRed}{\&}b\textcolor{BrickRed}{,}\ \textbf{\textcolor{Blue}{const}}\ point\ \textcolor{BrickRed}{\&}pnt\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
10 \mbox{}\ \ \textcolor{ForestGreen}{double}\ u\ \textcolor{BrickRed}{=}\ \textcolor{BrickRed}{((}pnt\textcolor{BrickRed}{.}x\ \textcolor{BrickRed}{-}\ a\textcolor{BrickRed}{.}x\textcolor{BrickRed}{)*(}b\textcolor{BrickRed}{.}x\ \textcolor{BrickRed}{-}\ a\textcolor{BrickRed}{.}x\textcolor{BrickRed}{)}\ \textcolor{BrickRed}{+}\ \textcolor{BrickRed}{(}pnt\textcolor{BrickRed}{.}y\ \textcolor{BrickRed}{-}\ a\textcolor{BrickRed}{.}y\textcolor{BrickRed}{)*(}b\textcolor{BrickRed}{.}y\ \textcolor{BrickRed}{-}\ a\textcolor{BrickRed}{.}y\textcolor{BrickRed}{))}\ \textcolor{BrickRed}{/}\ \textbf{\textcolor{Black}{distsqr}}\textcolor{BrickRed}{(}a\textcolor{BrickRed}{,}\ b\textcolor{BrickRed}{);} \\
11 \mbox{}\ \ point\ intersection\textcolor{BrickRed}{;} \\
12 \mbox{}\ \ intersection\textcolor{BrickRed}{.}x\ \textcolor{BrickRed}{=}\ a\textcolor{BrickRed}{.}x\ \textcolor{BrickRed}{+}\ u\textcolor{BrickRed}{*(}b\textcolor{BrickRed}{.}x\ \textcolor{BrickRed}{-}\ a\textcolor{BrickRed}{.}x\textcolor{BrickRed}{);} \\
13 \mbox{}\ \ intersection\textcolor{BrickRed}{.}y\ \textcolor{BrickRed}{=}\ a\textcolor{BrickRed}{.}y\ \textcolor{BrickRed}{+}\ u\textcolor{BrickRed}{*(}b\textcolor{BrickRed}{.}y\ \textcolor{BrickRed}{-}\ a\textcolor{BrickRed}{.}y\textcolor{BrickRed}{);} \\
14 \mbox{}\ \ \textbf{\textcolor{Blue}{return}}\ \textbf{\textcolor{Black}{dist}}\textcolor{BrickRed}{(}pnt\textcolor{BrickRed}{,}\ intersection\textcolor{BrickRed}{);} \\
15 \mbox{}\textcolor{Red}{\}} \\
17 } \normalfont\normalsize